package com.edu.controller;

import com.edu.dao.OrderDao;
import com.edu.dao.UserDao;
import com.edu.data.User;
import com.edu.util.Validator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Map;

@Controller
@RequestMapping("/Order")
public class OrderController {

    @Autowired
    UserDao userDao;
    @Autowired
    OrderDao orderDao;

    @RequestMapping("/list")
    public String list(Model model, HttpServletRequest request){
        Validator validator = new Validator(Validator.toSingleParameters(request));
        String page = request.getParameter("page");
        int pageNo = 1;
        if (!Validator.isEmpty(page))
            pageNo = Integer.parseInt(page);
        String orderIdStr = request.getParameter("entityId");
        String userNameStr = request.getParameter("userName");
        String condition = "";
        if (!Validator.isEmpty(orderIdStr))
            condition = condition + " EASYBUY_ORDER.eo_id=" + orderIdStr;
        if (!Validator.isEmpty(userNameStr)) {
            if (condition.length() > 0)
                condition = condition + " and ";
            condition = condition + "eo_user_name like '%" + userNameStr + "%'";
        }
        //如果是普通用户登录
        HttpSession session = request.getSession();
        User user=(User) session.getAttribute("loginUser");
        if(!(user.getEuStatus()==2)){
            if (condition.length() > 0)
                condition = condition + " and  EASYBUY_ORDER.EO_USER_ID ='" + user.getEuUserId()+"'";
            else
                condition = condition + "  EASYBUY_ORDER.EO_USER_ID ='" + user.getEuUserId()+"'";
        }
//        long rowCount = orderService.getOrderRowCount(condition);
//        String rowPerPage = request.getParameter("rowPerPage");
//        Pager pager = new Pager(rowCount, pageNo);
//        if (!Validator.isEmpty(rowPerPage))
//            pager = new Pager(rowCount, Integer.parseInt(rowPerPage), pageNo);
//        //获取订单及其详情
//        Map<Order, ArrayList<Product>> map = orderService.getOrders(condition, pager);
//
//        request.setAttribute("orders", map);
//        request.setAttribute("pager", pager);
//        request.setAttribute("pageNo", pageNo);
        return "";
    }


}
